<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get and/or set the current session name</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.session-module-name.html">session_module_name</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.session-regenerate-id.html">session_regenerate_id</a></div>
 <div class="up"><a href="ref.session.html">Session 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.session-name" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">session_name</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">session_name</span> &mdash; <span class="dc-title">Get and/or set the current session name</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.session-name-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>session_name</strong></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$name</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>session_name()</strong></span> returns the name of the current
   session. If <em><code class="parameter">name</code></em> is given,
   <span class="function"><strong>session_name()</strong></span> will update the session name and return
   the <em>old</em> session name.
  </p>
  <p class="para">
   The session name is reset to the default value stored in
   <em>session.name</em> at request startup time. Thus, you need to
   call <span class="function"><strong>session_name()</strong></span> for every request (and before
   <span class="function"><a href="function.session-start.html" class="function">session_start()</a></span> or <span class="function"><a href="function.session-register.html" class="function">session_register()</a></span>
   are called).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.session-name-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">name</code></em></dt>

     <dd>

      <p class="para">
       The session name references the name of the session, which is 
       used in cookies and URLs (e.g. <em>PHPSESSID</em>). It
       should contain only alphanumeric characters; it should be short and
       descriptive (i.e. for users with enabled cookie warnings).
       If <em><code class="parameter">name</code></em> is specified, the name of the current
       session is changed to its value.
      </p>
      <p class="para">
       <div class="warning"><strong class="warning">Warning</strong>
        <p class="para">
         The session name can&#039;t consist of digits only, at least one letter
         must be present. Otherwise a new session id is generated every time.
        </p>
       </div>
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.session-name-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the name of the current session.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.session-name-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4670">
    <p><strong>Example #1 <span class="function"><strong>session_name()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;set&nbsp;the&nbsp;session&nbsp;name&nbsp;to&nbsp;WebsiteID&nbsp;*/<br /><br /></span><span style="color: #0000BB">$previous_name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">session_name</span><span style="color: #007700">(</span><span style="color: #DD0000">"WebsiteID"</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"The&nbsp;previous&nbsp;session&nbsp;name&nbsp;was&nbsp;</span><span style="color: #0000BB">$previous_name</span><span style="color: #DD0000">&lt;br&nbsp;/&gt;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.session-name-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">
     The <a href="session.configuration.html#ini.session.name" class="link">session.name</a> configuration
     directive
    </li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.session-module-name.html">session_module_name</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.session-regenerate-id.html">session_regenerate_id</a></div>
 <div class="up"><a href="ref.session.html">Session 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
